home *** CD-ROM | disk | FTP | other *** search
/ Aminet 1 / Aminet - June 1993 [Walnut Creek].iso / usenet / sources / volume90 / rexx / dalf / part01
Encoding:
Internet Message Format  |  1990-07-15  |  12.5 KB

  1. Path: xanth!cs.odu.edu!Amiga-Request
  2. From: Amiga-Request@cs.odu.edu (Amiga Sources/Binaries Moderator)
  3. Newsgroups: comp.sources.amiga
  4. Subject: v90i212: dalf.rexx - Amiga Load File dump program in ARexx, Part01/01
  5. Message-ID: <13133@xanth.cs.odu.edu>
  6. Date: 15 Jul 90 22:46:37 GMT
  7. Sender: tadguy@cs.odu.edu
  8. Reply-To: micke@slaka.sirius.se (Mikael Karlsson)
  9. Lines: 376
  10. Approved: tadguy@cs.odu.edu (Tad Guy)
  11. X-Mail-Submissions-To: Amiga@cs.odu.edu
  12. X-Post-Discussions-To: comp.sys.amiga
  13.  
  14. Submitted-by: micke@slaka.sirius.se (Mikael Karlsson)
  15. Posting-number: Volume 90, Issue 212
  16. Archive-name: rexx/dalf/part01
  17.  
  18. [ this was submitted with no documentation  ...tad ]
  19.  
  20.  
  21.  
  22.  
  23. #!/bin/sh
  24. # This is a shell archive.  Remove anything before this line, then unpack
  25. # it by saving it into a file and typing "sh file".  To overwrite existing
  26. # files, type "sh file -c".  You can also feed this as standard input via
  27. # unshar, or by typing "sh <file", e.g..  If this archive is complete, you
  28. # will see the following message at the end:
  29. #        "End of archive 1 (of 1)."
  30. # Contents:  dalf.rexx
  31. # Wrapped by tadguy@xanth on Sun Jul 15 18:46:27 1990
  32. PATH=/bin:/usr/bin:/usr/ucb ; export PATH
  33. if test -f 'dalf.rexx' -a "${1}" != "-c" ; then 
  34.   echo shar: Will not clobber existing file \"'dalf.rexx'\"
  35. else
  36. echo shar: Extracting \"'dalf.rexx'\" \(10360 characters\)
  37. sed "s/^X//" >'dalf.rexx' <<'END_OF_FILE'
  38. X/************************************************\
  39. X*       dalf.rexx - Dumps Amiga Load Files.      *
  40. X* C 1990 Mikael Karlsson (micke@slaka.sirius.se) *
  41. X\************************************************/
  42. X
  43. Xparse arg file              /* File to examine */
  44. X
  45. Xsignal on break_c           /* We want a nice clean break */
  46. X
  47. Xpl. = "s"                   /* This is how to handle plurals the ince way */
  48. Xpl.1 = ""
  49. X
  50. Xtemp = '00'x
  51. Xflagtext.temp = ""
  52. Xtemp = '40'x                /* Bit 30 means 'Load to CHIPMEM' */
  53. Xflagtext.temp = " (CHIP)"
  54. Xbits. = '00'x
  55. X
  56. Xtype. = "Unknown"
  57. X
  58. X/* These are the hunk types we know about (so far) */
  59. X
  60. XHunk_unit    = '03E7'x; type.Hunk_unit    = "Hunk_unit    "
  61. XHunk_name    = '03E8'x; type.Hunk_name    = "Hunk_name    "
  62. XHunk_code    = '03E9'x; type.Hunk_code    = "Hunk_code    "
  63. XHunk_data    = '03EA'x; type.Hunk_data    = "Hunk_data    "
  64. XHunk_bss     = '03EB'x; type.Hunk_bss     = "Hunk_bss     "
  65. XHunk_reloc32 = '03EC'x; type.Hunk_reloc32 = "Hunk_reloc32 "
  66. XHunk_reloc16 = '03ED'x; type.Hunk_reloc16 = "Hunk_reloc16 "
  67. XHunk_reloc8  = '03EE'x; type.Hunk_reloc8  = "Hunk_reloc8  "
  68. XHunk_ext     = '03EF'x; type.Hunk_ext     = "Hunk_ext     "
  69. XHunk_symbol  = '03F0'x; type.Hunk_symbol  = "Hunk_symbol  "
  70. XHunk_debug   = '03F1'x; type.Hunk_debug   = "Hunk_debug   "
  71. XHunk_end     = '03F2'x; type.Hunk_end     = "Hunk_end     "
  72. XHunk_header  = '03F3'x; type.Hunk_header  = "Hunk_header  "
  73. XHunk_overlay = '03F5'x; type.Hunk_overlay = "Hunk_overlay "
  74. XHunk_break   = '03F6'x; type.Hunk_break   = "Hunk_break   "
  75. XHunk_drel32  = '03F7'x; type.Hunk_drel32  = "Hunk_drel32  "
  76. XHunk_drel16  = '03F8'x; type.Hunk_drel16  = "Hunk_drel16  "
  77. XHunk_drel8   = '03F9'x; type.Hunk_drel8   = "Hunk_drel8   "
  78. XHunk_libhunk = '03FA'x; type.Hunk_libhunk = "Hunk_libhunk "
  79. XHunk_libindx = '03FB'x; type.Hunk_libindx = "Hunk_libindx "
  80. X
  81. X/* These are subtypes in Hunk_ext */
  82. X
  83. XHunk_def     =   '01'x; type.Hunk_def     = "Hunk_def    "
  84. XHunk_abs     =   '02'x; type.Hunk_abs     = "Hunk_abs    "
  85. XHunk_res     =   '03'x; type.Hunk_res     = "Hunk_res    "
  86. XHunk_ext32   =   '81'x; type.Hunk_ext32   = "Hunk_ext32  "
  87. XHunk_ext16   =   '83'x; type.Hunk_ext16   = "Hunk_ext16  "
  88. XHunk_ext8    =   '84'x; type.Hunk_ext8    = "Hunk_ext8   "
  89. XHunk_dext32  =   '85'x; type.Hunk_dext32  = "Hunk_dext32 "
  90. XHunk_dext16  =   '86'x; type.Hunk_dext16  = "Hunk_dext16 "
  91. XHunk_dext8   =   '87'x; type.Hunk_dext8   = "Hunk_dext8  "
  92. X
  93. Xif ~open(lf, file, 'R') then do     /* Open load file */
  94. X    say "Can't open" file
  95. X    exit 10
  96. Xend
  97. X
  98. Xindex = 0
  99. Xsize. = 0
  100. X
  101. Xloop:
  102. X    type = readch(lf, 4)            /* Read hunk type */
  103. X    if type == "" then do           /* End of file */
  104. X        signal done
  105. X    end
  106. X    bits.index = bitor(bits.index, left(type, 1))   /* Check flag bits */
  107. X    type = right(type, 2)                           /* Remove flag bits */
  108. X    if type.type = "Unknown"  then do
  109. X        say "Unknown hunk type ("c2x(type)")"
  110. X        exit 10
  111. X    end
  112. X    id = type.type "("c2x(type)")"
  113. X    signal value trim(type.type)    /* Jump to hunk display routine */
  114. X
  115. XHunk_header:
  116. X    say id
  117. X    dummy = c2d(readch(lf, 4))         /* What's this? */
  118. X    count = c2d(readch(lf, 4))
  119. X    low   = c2d(readch(lf, 4))
  120. X    high  = c2d(readch(lf, 4))
  121. X    say "      "count "hunk"pl.count "("low "to" high")"
  122. X    do i=low to high
  123. X        size = readch(lf, 4)
  124. X        bits.i = left(size, 1)
  125. X        size.i = c2d(right(size, 3))*4
  126. X        bits = bits.i
  127. X        say "      Size hunk" i":" size.i "bytes" flagtext.bits
  128. X    end
  129. X    index = low
  130. X    signal loop
  131. X
  132. XHunk_end:
  133. X    say "    "id
  134. X    signal loop
  135. X
  136. XHunk_code:
  137. X    size = readch(lf, 4)
  138. X    bits = bitor(bits.index, left(size, 1))
  139. X    size = c2d(right(size, 3))*4
  140. X    temp = right(index, 2)
  141. X    temp = temp":" id
  142. X    temp = temp "("size "bytes)"flagtext.bits
  143. X    say temp
  144. X    do while size>32768
  145. X        data = readch(lf, 32768)
  146. X        size = size-32768
  147. X    end
  148. X    data = readch(lf, size)
  149. X    index = index+1
  150. X    signal loop
  151. X
  152. XHunk_reloc32:
  153. XHunk_reloc16:
  154. XHunk_reloc8:
  155. X    say "    "id
  156. X    count = c2d(readch(lf, 4))
  157. X    do while count~=0
  158. X        ref = c2d(readch(lf, 4))
  159. X        say "      "count "item"pl.count "for hunk" ref
  160. X        refs = readch(lf, count*4)
  161. X        count = c2d(readch(lf, 4))
  162. X    end
  163. X    signal loop
  164. X
  165. XHunk_ext:
  166. X    say "    "id
  167. X    sym_type = readch(lf, 1)
  168. X    sym_length = c2d(readch(lf, 3))*4
  169. X    do until sym_type == "00"x
  170. X        symbol = strip(readch(lf, sym_length), 'T', '00'x)
  171. X        select
  172. X            when sym_type == hunk_def |,
  173. X                 sym_type == hunk_abs |,
  174. X                 sym_type == hunk_res then do
  175. X                offset = strip(c2x(readch(lf, 4)), 'T', '00'x)
  176. X                temp = "     " type.sym_type
  177. X                temp = temp left(symbol, 32)":" "0x"offset
  178. X                say temp
  179. X            end
  180. X            when sym_type == hunk_ext32  |,
  181. X                 sym_type == hunk_ext16  |,
  182. X                 sym_type == hunk_ext8   |,
  183. X                 sym_type == hunk_dext32 |,
  184. X                 sym_type == hunk_dext16 |,
  185. X                 sym_type == hunk_dext8 then do
  186. X                count = c2d(readch(lf, 4))
  187. X                refs = readch(lf, count*4)
  188. X                temp = "     " type.sym_type
  189. X                temp = temp left(symbol, 32)":"
  190. X                temp = temp right(count, 2) "item"pl.count
  191. X                say temp
  192. X            end
  193. X            otherwise do
  194. X                say "      Unknown definition"
  195. X            end
  196. X        end
  197. X        sym_type = readch(lf, 1)
  198. X        sym_length = c2d(readch(lf, 3))*4
  199. X    end
  200. X    signal loop
  201. X
  202. XHunk_drel32:
  203. XHunk_drel16:
  204. XHunk_drel8:
  205. X    say "    "id
  206. X    count = c2d(readch(lf, 4))
  207. X    do while count~=0
  208. X        ref = c2d(readch(lf, 4))
  209. X        say "      "count "item"pl.count "for hunk" ref
  210. X        refs = readch(lf, count*4)
  211. X        count = c2d(readch(lf, 4))
  212. X    end
  213. X    signal loop
  214. X
  215. XHunk_data:
  216. X    size = readch(lf, 4)
  217. X    bits = bitor(bits.index, left(size, 1))
  218. X    size = c2d(right(size, 3))*4
  219. X    temp = right(index, 2)
  220. X    temp = temp":" id
  221. X    temp = temp "("size "bytes"
  222. X    if size.index-size>0 then do
  223. X        temp = temp"," size.index-size "BSS"
  224. X    end
  225. X    temp = temp")"flagtext.bits
  226. X    say temp
  227. X    data = readch(lf, size)
  228. X    index = index+1
  229. X    signal loop
  230. X
  231. XHunk_bss:
  232. X    size = readch(lf, 4)
  233. X    bits = bitor(bits.index, left(size, 1))
  234. X    size = c2d(right(size, 3))*4
  235. X    temp = right(index, 2)
  236. X    temp = temp":" id
  237. X    temp = temp "("size "bytes)"flagtext.bits
  238. X    say temp
  239. X    index = index+1
  240. X    signal loop
  241. X
  242. XHunk_unit:
  243. XHunk_name:
  244. X    say right(index, 2)":"id
  245. X    size = c2d(readch(lf, 4))*4
  246. X    data = readch(lf, size)
  247. X    say "    " type.type":" data
  248. X    index = index+1
  249. X    signal loop
  250. X
  251. XHunk_symbol:
  252. X    say right(index, 2)":"id
  253. X    size = c2d(readch(lf, 4))*4
  254. X    do while size~=0
  255. X        data = strip(readch(lf, size), 'T', '00'x)
  256. X        say "    " left(data, 32)":" c2x(readch(lf, 4))
  257. X        size = c2d(readch(lf, 4))*4
  258. X    end
  259. X    signal loop
  260. X
  261. XHunk_libhunk:
  262. X    size = readch(lf, 4)
  263. X    bits = bitor(bits.index, left(size, 1))
  264. X    size = c2d(right(size, 3))*4
  265. X    say "    "id "("size "bytes)"flagtext.bits
  266. X    signal loop
  267. X
  268. XHunk_libindx:
  269. X    size = c2d(readch(lf, 4))*4
  270. X    say "    "id "("size "bytes)"
  271. X    count = c2d(readch(lf, 2))
  272. X    say "    " count "bytes in string block"
  273. X    string = readch(lf, count)
  274. X    do forever
  275. X        nameoffset = c2d(readch(lf, 2))
  276. X        if nameoffset=0 then leave
  277. X        parse value substr(string, nameoffset+1) with name "00"x .
  278. X        say "    PUNIT '"name"'"
  279. X        unitoffset = c2d(readch(lf, 2))
  280. X        say "     offset" unitoffset "longword"pl.unitoffset
  281. X        hunkcount = c2d(readch(lf, 2))
  282. X        say "    " hunkcount "hunk"pl.hunkcount
  283. X        do for hunkcount
  284. X            nameoffset = c2d(readch(lf, 2))
  285. X            parse value substr(string, nameoffset+1) with name "00"x .
  286. X            hunksize = c2d(readch(lf, 2))
  287. X            hunktype = readch(lf, 2)
  288. X            say "    " type.hunktype "'"name"' of" hunksize "longword"pl.hunksize
  289. X            refcount = c2d(readch(lf, 2))
  290. X            say "    " refcount "ref"pl.refcount":"
  291. X            do for refcount
  292. X                nameoffset = c2d(readch(lf, 2))
  293. X                if substr(string, nameoffset+1, 1)="00"x then do
  294. X                    nameoffset = nameoffset+1
  295. X                    temp = "16"
  296. X                end
  297. X                else do
  298. X                    temp = "32"
  299. X                end
  300. X                parse value substr(string, nameoffset+1) with name "00"x .
  301. X                say "      " temp"-bit ref '"name"'"
  302. X            end
  303. X            defcount = c2d(readch(lf, 2))
  304. X            say "    " defcount "def"pl.defcount":"
  305. X            do for defcount
  306. X                nameoffset = c2d(readch(lf, 2))
  307. X                parse value substr(string, nameoffset+1) with name "00"x .
  308. X                defoffset = readch(lf, 2)
  309. X                defdata = readch(lf, 2)
  310. X                deftype = c2d(right(defdata, 2))
  311. X                defdata = left(defdata, 2)
  312. X                select
  313. X                    when deftype=1 then do
  314. X                        say "       Define def '"name"' at" c2d(defoffset)
  315. X                    end
  316. X                    when deftype=2 then do
  317. X                        defoffset = defdata || defoffset
  318. X                        say "       Define abs '"name"' at" c2d(defoffset)
  319. X                    end
  320. X                    when deftype=3 then do
  321. X                        say "       Define res '"name"' at" c2d(defoffset)
  322. X                    end
  323. X                    when deftype=66 then do
  324. X                        defoffset = "FF"x || defdata || defoffset
  325. X                        say "       Define abs '"name"' at" c2d(defoffset)
  326. X                    end
  327. X                    otherwise do
  328. X                        say "Error in object file"
  329. X                        exit 10
  330. X                    end
  331. X                end
  332. X            end
  333. X        end
  334. X    end
  335. X    signal loop
  336. X
  337. XHunk_debug:
  338. X    size = c2d(readch(lf, 4))*4
  339. X    say "    "id "("size "bytes)"
  340. X    say "       Offset:" c2d(readch(lf, 4))
  341. X    say "       Type:  " readch(lf, 4)
  342. X    data = readch(lf, size-8)
  343. X    signal loop
  344. X
  345. XHunk_break:
  346. X    size = c2d(readch(lf, 4))*4
  347. X    say "    "id "("size "bytes)"
  348. X    data = readch(lf, size)
  349. X    index = index+1
  350. X    signal loop
  351. X
  352. XHunk_overlay:
  353. X    size = c2d(readch(lf, 4))*4
  354. X    say "    "id "("size "bytes) - Not supported"
  355. X    data = readch(lf, size)
  356. X    index = index+1
  357. X    signal loop
  358. X
  359. X
  360. Xbreak_c:
  361. Xdone:
  362. Xexit 0
  363. END_OF_FILE
  364. if test 10360 -ne `wc -c <'dalf.rexx'`; then
  365.     echo shar: \"'dalf.rexx'\" unpacked with wrong size!
  366. fi
  367. # end of 'dalf.rexx'
  368. fi
  369. echo shar: End of archive 1 \(of 1\).
  370. cp /dev/null ark1isdone
  371. MISSING=""
  372. for I in 1 ; do
  373.     if test ! -f ark${I}isdone ; then
  374.     MISSING="${MISSING} ${I}"
  375.     fi
  376. done
  377. if test "${MISSING}" = "" ; then
  378.     echo You have the archive.
  379.     rm -f ark[1-9]isdone
  380. else
  381.     echo You still need to unpack the following archives:
  382.     echo "        " ${MISSING}
  383. fi
  384. ##  End of shell archive.
  385. exit 0
  386. -- 
  387. Mail submissions (sources or binaries) to <amiga@cs.odu.edu>.
  388. Mail comments to the moderator at <amiga-request@cs.odu.edu>.
  389. Post requests for sources, and general discussion to comp.sys.amiga.
  390.